package dl.jf.web.ajax.admin;

import java.util.ArrayList;
import java.util.List;

import dl.jf.common.model.LabelValue;
import dl.jf.common.model.MUser;
import dl.jf.service.iservice.admin.IAdminMemberService;
import dl.jf.web.ajax.BaseAjaxRequest;
import net.sf.json.JSONArray;

public class AdminAjaxRequest extends BaseAjaxRequest {

	public AdminAjaxRequest() {
		super("AdminAjaxRequest");
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1368971342136080683L;

	private JSONArray roleList;

	private JSONArray disabledList;
	
	private String result;
	
	public String getResult() {
		return result;
	}

	private String userId;
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	private IAdminMemberService adminMemberService;

	public IAdminMemberService getAdminMemberService() {
		return adminMemberService;
	}

	public void setAdminMemberService(IAdminMemberService adminMemberService) {
		this.adminMemberService = adminMemberService;
	}

	// ajax返回结果
	public JSONArray getRoleList() {
		return roleList;
	}

	public JSONArray getDisabledList() {
		return disabledList;
	}
	

	@Override
	public String execute() throws Exception {
		return "success";
	}

	public String getRoleLabelListById() {
		List<LabelValue> roleLabelList = null;
		try {
			roleLabelList = adminMemberService.getRoleLabelListById();
			this.roleList = JSONArray.fromObject(roleLabelList);
		} catch (Exception ex) {
			logger.error(ex.getMessage(), ex);
		}

		return "success";
	}

	public String getDisabledListById() {
		List<LabelValue> disabledList = new ArrayList<LabelValue>();
		try {
			disabledList.add(new LabelValue(getText("msg_admin_member_disabled_no"), "0"));
			disabledList.add(new LabelValue(getText("msg_admin_member_disabled_yes"), "1"));
			this.disabledList = JSONArray.fromObject(disabledList);
		} catch (Exception ex) {
			logger.error(ex.getMessage(), ex);
		}

		return "success";
	}
	
	public String checkExistUser() {
		MUser user = null;
		try {
			user = adminMemberService.getUserListByUserId(this.userId);
		} catch (Exception ex) {
			logger.error(ex.getMessage(), ex);
		}
		if(user == null){
			this.result = "";
		} else {
			this.result = getText("global.warning.user.exists");
		}
		return "success";
	}
}
